<template>
  <el-dialog title="审核充值记录" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
      <el-form-item label="企业名称" prop="title">
        <span>{{dataForm.title}}</span>
      </el-form-item>
      <el-form-item label="付款账号" prop="payer_number" v-if="dataForm.type == 1">
        <span>{{dataForm.payer_number}}</span>
      </el-form-item>
      <el-form-item label="充值金额" prop="amount" v-if="dataForm.type == 1">
        <span style="color: #F56C6C">{{dataForm.amount}}</span>
      </el-form-item>
      <el-form-item label="退款金额" prop="amount" v-else>
        <span style="color: #F56C6C">{{dataForm.amount}}</span>
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <span>{{dataForm.remark}}</span>
      </el-form-item>
      <el-form-item label="状态" size="mini" prop="status">
        <el-radio-group v-model="dataForm.status">
          <el-radio :label="-1">审核拒绝</el-radio>
          <el-radio :label="2">审核通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="审核原因" prop="reason">
        <el-input type="textarea" v-model="dataForm.reason" :rows="4" placeholder="审核原因"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">提交</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          title: '',
          payer_number: '',
          amount: '',
          remark: '',
          reason: '',
          type: 1,
          status: 0
        },
        dataRule: {
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/recharge/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.title = data.recharge.title
                this.dataForm.payer_number = data.recharge.payer_number
                this.dataForm.amount = data.recharge.amount
                this.dataForm.remark = data.recharge.remark
                this.dataForm.type = data.recharge.type
                //this.dataForm.reason = data.recharge.reason
                this.dataForm.status = data.recharge.status
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            if(this.dataForm.status == 0) {
              this.$message.error("请选择审核状态")
              return
            }
            if(this.dataForm.status == -1 && this.dataForm.reason.length <= 0) {
              this.$message.error("请输入拒绝理由")
              return
            }
            this.$http({
              url: this.$http.adornUrl(`/recharge/check/${this.dataForm.id}`),
              method: 'post',
              data: this.$http.adornData({
                'status': this.dataForm.status,
                'reason': this.dataForm.reason
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            }).catch((error) => {
              this.$message.error('请求异常')
            })
          }
        })
      }
    }
  }
</script>
